package com.apes.scm.stock.safetyStock.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.stock.model.Location;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @Classname SafetyStockGap
 * @Description 安全库存缺口日报表
 * @Date 2019/12/4 15:00
 * @Created by wsj
 */
@Entity
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@EntityListeners(DefaultPersistListener.class)
@Table(name = SafetyStockGap.CONST_TABLE_NAME,indexes = {@Index(name = "u_stock_safety_gap",columnList = "product_id,location_id,statistics_date", unique = true)})

public class SafetyStockGap extends Model {
    public static final  String CONST_TABLE_NAME = "stock_safety_gap";
    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "安全库存缺口日报表")
    private Long id;  //内码

    @Comment("仓库库区")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "location_id", referencedColumnName = "id", nullable = false)
    private Location location;  //仓库库区

    @Comment("商品编码")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id", nullable = false)
    private Product product;

    @Comment("统计日期")
    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Column(name = "statistics_date")
    private Date statisticsDate;

    @Comment("最高限量")
    @Column(name = "the_max_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double theMaxQty = 0.0;

    @Comment("最低限量")
    @Column(name = "the_min_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double theMinQty = 0.0;

    @Comment("安全库存")
    @Column(name = "safety_stock_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double safetyStockQty = 0.0;

    @Comment("可用数")
    @Column(name = "usable_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double usableQty = 0.0;

    @Comment("要货制单数量")
    @Column(name = "require_billing_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double requireBillingQty = 0.0;

    @Comment("订货在途")
    @Column(name = "purchasing_way_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double purchasingWayQty = 0.0;

    @Comment("转储收货在途")
    @Column(name = "transfer_receive_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double transferReceiveQty = 0.0;

    @Comment("冻结数量")
    @Column(name = "frozen_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double frozenQty = 0.0;

    @Comment("本仓缺口数量")
    @Column(name = "gap_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double gapQty = 0.0;

    @Comment("所辖门店缺口")
    @Column(name = "jurisdiction_store_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double jurisdictionStoreQty = 0.0;

    @Comment("合计数量")
    @Column(name = "total_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double totalQty = 0.0;

    @Column(name = "assigned_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("已分配数量")
    private double assignedQty = 0;

    @Comment("入库数量")
    @Column(name = "warehousing_qty", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    private double warehousingQty = 0.0;

    @Column(name = "done",columnDefinition = ApesConst.FIELD_BOOLEAN_FALSE, nullable = false)
    @Comment("完成标记")
    private Boolean done = false;
}
